<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:t="http://myfaces.apache.org/tomahawk"
	xmlns:ap="http://aplikata.com/facelets" template="/pages/template/main-layout.xhtml">

	<ui:define name="content">
		<t:saveState value="#{evokPatientTherapyBean.qyPatientName}" />
		<t:saveState value="#{evokPatientTherapyBean.patientTherapy}" />
		
		<h:panelGrid columns="2" cellpadding="3" width="100%" columnClasses="width30,width70">

			<h:panelGrid width="100%" id="pnlquery">
				<p:panel>
					<h:panelGrid columns="2" cellpadding="5" width="100%">
						<h:outputLabel for="patientname" value="#{msgs.default_name_surname}" />
						<p:autoComplete completeMethod="#{evokPatientTherapyBean.completeQueryName}" id="patientname"
							size="40" value="#{evokPatientTherapyBean.qyPatientName}" forceSelection="true"
							minQueryLength="3">
							<p:ajax event="itemSelect" listener="#{evokPatientTherapyBean.selectPatientName}"
								update=":messages,:mainform:patientlist, :mainform:therapylist, :mainform:pnlinfo" />
						</p:autoComplete>
					</h:panelGrid>
					<f:facet name="footer">
						<p:commandButton value="#{msgs.button_reset}" icon="ui-icon-arrowrefresh-1-n"
							immediate="true" oncomplete="wdgTherapyTab.select(0);"
							autoSubmit="false" actionListener="#{evokPatientTherapyBean.resetQuery}"
							update="patientname, patientlist, therapylist, :mainform:pnlinfo" />
					</f:facet>
				</p:panel>

				<p:dataTable var="lo" id="patientlist" value="#{evokPatientTherapyBean.domainPatientModel}"
					selectionMode="single" rowKey="#{lo.id}" widgetVar="wdgPatientList" emptyMessage="">
					<p:ajax event="rowSelect" listener="#{evokPatientTherapyBean.selectDomainPatient}"
						update=":mainform:therapylist,:mainform:pnlinfo" />

					<p:column headerText="#{msgs.default_name_surname}">
						<h:outputText value="#{lo.patient.surname} #{lo.patient.name}" />
					</p:column>

					<p:column headerText="#{msgs.table_column_operation}" styleClass="gridNoBorder">
						<h:panelGrid width="100%" columns="2" columnClasses="left,right">
							<p:commandLink update=":dialogform:patientDialog"
								actionListener="#{evokPatientTherapyBean.queryPatient}"
								oncomplete="patientDialog.show();wdgPatientList.unselectAllRows();"
								styleClass="ui-icon ui-icon-search" title="#{msgs.default_basic_data_label}">
							</p:commandLink>

							<p:commandLink update=":mainform:pnlinfo, :mainform:therapylist"
								actionListener="#{evokPatientTherapyBean.addTherapy}" styleClass="ui-icon ui-icon-plus"
								title="#{msgs.patient_therapy_add_title}">
							</p:commandLink>
						</h:panelGrid>
					</p:column>
				</p:dataTable>

				<p:dataTable var="lo" id="therapylist" value="#{evokPatientTherapyBean.patientTherapyModel}"
					paginator="true" rows="15" paginatorTemplate="#{msgs.paginator}" paginatorPosition="bottom"
					currentPageReportTemplate="#{msgs.paginator_currentPage}" rowsPerPageTemplate="15,30,60"
					selectionMode="single" widgetVar="wdgTherapyList" rowKey="#{lo[0].id}" emptyMessage="">

					<p:ajax event="rowSelect" listener="#{evokPatientTherapyBean.selectPatientTherapy}"
						update=":mainform:pnlinfo" />

					<p:column style="width:16px">
						<p:rowToggler />
					</p:column>

					<p:column headerText="#{msgs.patient_therapy_startDate}">
						<h:outputText value="#{lo[0].startDate}">
							<f:convertDateTime pattern="dd/MM/yyyy" />
						</h:outputText>
					</p:column>

					<p:column headerText="#{msgs.patient_therapy_success}">
						<h:outputText value="#{lo[0].success}" converter="enumConverter" enumName="TherapySuccess" />
					</p:column>

					<p:column headerText="#{msgs.default_status}">
						<h:outputText value="#{lo[0].status}" converter="enumConverter" enumName="TherapyStatus" />
					</p:column>

					<p:rowExpansion>
						<h:outputText value="#{lo[1]}" escape="false" />
					</p:rowExpansion>
				</p:dataTable>
			</h:panelGrid>

			<h:panelGrid width="100%" id="pnlinfo">
				<h:panelGrid columns="2" width="100%" columnClasses="left,right">
					<p:commandButton value="#{msgs.button_delete}" icon="ui-icon-trash"
						oncomplete="confirmDeletePatientTherapy.show();" rendered="#{evokPatientTherapyBean.patientTherapy.id != null }"/>
						
					<p:commandButton value="#{msgs.button_print}" icon="ui-icon-print"
						rendered="#{evokPatientTherapyBean.patientTherapy.id != null}" ajax="false"
						actionListener="#{evokPatientTherapyBean.generatePdfReport}" />
				</h:panelGrid>

				<h:inputHidden value="#{evokPatientTherapyBean.patientTherapy.id}" />

				<p:tabView id="tabviewTherapy" activeIndex="#{evokPatientTherapyBean.tabIndex}" widgetVar="wdgTherapyTab">
					<p:ajax event="tabChange" listener="#{evokPatientTherapyBean.onTabChange}" />

					<p:tab id="therapyBasicInfo" title="#{msgs.patient_therapy_basic}">
						<ui:include src="patient_therapy_basic.xhtml" />
					</p:tab>

					<p:tab id="therapyProcessInfo" title="#{msgs.patient_therapy_process}"
						rendered="#{evokPatientTherapyBean.patientTherapy.id != null and evokPatientTherapyBean.patientTherapy.id != 0 }">
						<h:panelGrid width="100%">
							<ap:dynamicCategoryTable value="#{evokPatientTherapyBean.pnList}" id="therapyprocess"
								readonly="false" />
							<f:facet name="footer">
								<h:panelGroup style="float:right;">
									<p:commandButton value="#{msgs.button_submit}" icon="ui-icon-disk"
										actionListener="#{evokPatientTherapyBean.submit}"
										update=":mainform:pnlinfo,:messages,:mainform:pnlquery" />
								</h:panelGroup>
							</f:facet>
						</h:panelGrid>
					</p:tab>

					<p:tab id="reservation" title="#{msgs.patient_reservations}">
						<ui:include src="patient_reservation.xhtml" />
					</p:tab>

					<p:tab id="qtnaireInfo" title="#{msgs.patient_therapy_qtnaires}"
						rendered="#{evokPatientTherapyBean.patientTherapy.id != null and evokPatientTherapyBean.patientTherapy.id != 0 }">
						<ui:include src="patient_therapy_qtnaire.xhtml" />
					</p:tab>

					<p:tab id="uploadInfo" title="#{msgs.evok_patient_document}"
						rendered="#{evokPatientTherapyBean.patientTherapy.id != null and evokPatientTherapyBean.patientTherapy.id != 0 }">
						<ui:include src="patient_therapy_upload.xhtml" />
					</p:tab>

					<p:tab id="therapyServiceInfo" title="#{msgs.therapy_service_plural}"
						rendered="#{evokPatientTherapyBean.patientTherapy.id != null and evokPatientTherapyBean.patientTherapy.id != 0 }">
						<ui:include src="patient_therapy_service.xhtml" />
					</p:tab>

					<p:tab id="commentInfo" title="#{msgs.comment} (#{evokPatientTherapyBean.unreadComments}) "
						rendered="#{evokPatientTherapyBean.patientTherapy.id != null and evokPatientTherapyBean.patientTherapy.id != 0 }">
						<ui:include src="patient_therapy_comment.xhtml" />
					</p:tab>
				</p:tabView>
			</h:panelGrid>
		</h:panelGrid>
	</ui:define>

	<ui:define name="dialog">
		<ui:include src="/pages/aplikata/evok/dialog/patient_dialog.xhtml" />
		<h:panelGroup id="qtnairePanelGroup">
			<ui:include src="/pages/aplikata/evok/dialog/qtnaire/qtnaire_dialog_basic.xhtml" />
		</h:panelGroup>

		<h:panelGrid>
			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="#{msgs.default_alert}" severity="alert"
				widgetVar="confirmQtnaireDelete" modal="true" id="deleteQtD">

				<p:commandButton value="#{msgs.button_and}"
					update=":messages,:mainform:tabviewTherapy:qtnirePanelGrid"
					actionListener="#{evokPatientQtnaireBean.deleteAction}"
					oncomplete="confirmQtnaireDelete.hide()" />

				<p:commandButton value="#{msgs.button_not}" onclick="confirmQtnaireDelete.hide()" type="button" />
			</p:confirmDialog>

			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="POZOR" severity="alert" widgetVar="confirmDeletePatientTherapy"
				modal="true">
				<p:commandButton value="DA" style="float:left"
					update=":messages,:mainform:pnlinfo,:mainform:pnlquery"
					actionListener="#{evokPatientTherapyBean.delete}"
					oncomplete="confirmDeletePatientTherapy.hide()" />
				<p:commandButton value="NE" style="float:right" onclick="confirmDeletePatientTherapy.hide()"
					type="button" />
			</p:confirmDialog>

			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="POZOR" severity="alert" widgetVar="confirmDeleteTherapyService"
				modal="true">

				<p:commandButton value="DA"
					update=":messages,:mainform:tabviewTherapy:servicelist,:mainform:tabviewTherapy:pnlservice"
					actionListener="#{evokPatientTherapyBean.deleteTherapyService}"
					oncomplete="confirmDeleteTherapyService.hide()" />

				<p:commandButton value="NE" onclick="confirmDeleteTherapyService.hide()" type="button" />
			</p:confirmDialog>

			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="POZOR" severity="alert" widgetVar="confirmDeleteAtt" modal="true">

				<p:commandButton value="DA"
					update=":messages,:mainform:tabviewTherapy:pnlUploadInfo,:mainform:tabviewTherapy:tblAtt"
					actionListener="#{evokPatientTherapyBean.deleteAtt}" oncomplete="confirmDeleteAtt.hide()" />

				<p:commandButton value="NE" onclick="confirmDeleteAtt.hide()" type="button" />
			</p:confirmDialog>

			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="POZOR" severity="alert" widgetVar="confirmDeleteReservation"
				modal="true">

				<p:commandButton value="DA" update=":mainform:tabviewTherapy:tblReservationList,:messages"
					actionListener="#{evokPatientTherapyBean.deleteDoctorReservation}"
					oncomplete="confirmDeleteReservation.hide()" />

				<p:commandButton value="NE" onclick="confirmDeleteReservation.hide()" type="button" />
			</p:confirmDialog>

		</h:panelGrid>
	</ui:define>
</ui:composition>
